package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.util.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.atguigu.gmall.product.service.BaseTrademarkService;

import org.springframework.web.bind.annotation.RestController;

/**
 * 品牌表 前端控制器
 *
 * @author lhw
 * @since 2022-12-25
 */
@Api(tags = "品牌表控制器")
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    @ApiOperation("品牌分页查询")
    @GetMapping("/{page}/{limit}")
    public Result<IPage<BaseTrademark>> baseTrademarkByPage(
            @PathVariable("page") Long page,@PathVariable("limit")Long limit
    ){
        //封装分页请求参数
        IPage<BaseTrademark> iPage = new Page<>(page,limit);
        //调用业务逻辑实现分页查询
        iPage = baseTrademarkService.baseTrademarkByPage(iPage);
        return Result.ok(iPage);
    }

    @ApiOperation("根据品牌id获取品牌对象")
    @GetMapping("/get/{id}")
    public Result<BaseTrademark> getById(@PathVariable("id")Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("修改品牌信息")
    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌信息")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id")Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("保存品牌信息")
    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

}
